#!/bin/sh
#
# cyclictest service for continuous real-time monitoring
#

DAEMON="cyclictest"
PIDFILE="/var/run/$DAEMON.pid"
LOGFILE="/var/log/$DAEMON.log"

start() {
    printf "Starting $DAEMON: "
    runandreportcyclictest > $LOGFILE 2>&1 &
    echo $! > $PIDFILE
    echo "OK"
}

stop() {
    printf "Stopping $DAEMON: "
    kill $(cat $PIDFILE)
    rm -f $PIDFILE
    echo "OK"
}

restart() {
    stop
    sleep 1
    start
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?
